<?php

namespace app\admin\validate;

use think\Validate;

class UserValidate extends Validate
{
    protected $rule = [
        'username' => 'require|min:6|unique:user',
        'password' => 'require|min:6',
        'repassword' => 'require|confirm:password',
        "id" => 'require',
        "status" => 'require|in:1,-1',
        "contact_email"=>"email"
    ];

    protected $message = [
        'username.require' => '用户名必须填写',
        'username.min' => '用户名长度不能少于6个字符',
        'username.unique' => '用户名已经存在',
        'password.require' => '密码必须填写',
        'password.min' => '密码长度不能小于6个字符',
        'repassword' => "密码两次不一致",
        "id.require" => "缺少id",
        "status.in" => "状态值错误",
        "status.require" => "缺少状态值",
        "contact_email.email"=>"邮箱格式错误"
    ];

    protected $scene = [
        'login' => ['username', 'password'],
        'add' => ['username',"username","email"],
        'status' => ["id", "status"],
        'edit' => ['id','email'],
        'passwd'=>['id',  'password', 'repassword'],
        'info'=>['email'],
        "mypassword"=>['password', 'repassword']
    ];

    public function sceneLogin()
    {
        return $this->only(['username','password'])
            ->remove('username', 'unique');
    }
}